package com.handle;

import com.constant.PromiseConstant;
import com.message.rpc.RpcResponseMessage;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.Promise;
import lombok.extern.slf4j.Slf4j;

/**
 * @author linyu.dai
 * @project rpc
 * @description
 * @creat 2022/11/28 09:08:58
 */
@Slf4j
@ChannelHandler.Sharable
public class RpcResponseHandle extends SimpleChannelInboundHandler<RpcResponseMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, RpcResponseMessage msg) throws Exception {
        log.info("rpc 返回值{}", msg);
        Promise<Object> promise = PromiseConstant.getPromise(msg.getMessageId());
        promise.setSuccess(msg);
    }
}
